<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>配送人员名单</title>
</head>
<body>
    <div th:fragment="content">
        <div class="container-fluid">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h2 class="h3">配送人员名单</h2>
                <div>
                    <button class="btn btn-primary" onclick="refreshData()">
                        <i class="fas fa-sync-alt me-1"></i> 刷新数据
                    </button>
                </div>
            </div>

            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="card-title mb-0">配送员列表</h5>
                    <div class="d-flex">
                        <input type="text" class="form-control me-2" placeholder="搜索配送员..." id="searchInput">
                        <button class="btn btn-outline-primary" onclick="searchCouriers()">
                            <i class="fas fa-search"></i>
                        </button>
                    </div>
                </div>
                <div class="card-body">
                    <div class="table-container">
                        <table class="data-table">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>姓名</th>
                                    <th>联系电话</th>
                                    <th>服务区域</th>
                                    <th>总订单数</th>
                                    <th>当前状态</th>
                                    <th>最后登录</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr th:each="courier : ${couriers}" th:if="${couriers != null && !couriers.isEmpty()}">
                                    <td th:text="${courier.courierId}">1</td>
                                    <td th:text="${courier.username}">张三</td>
                                    <td th:text="${courier.phone}">13812345678</td>
                                    <td>
                                        <span th:each="region, iterStat : ${courier.regions}" class="badge badge-primary me-1" th:text="${region}">
                                            区域名称
                                        </span>
                                    </td>
                                    <td th:text="${courier.totalOrders}">120</td>
                                    <td>
                                        <span th:if="${courier.currentStatus == 'idle'}" class="badge badge-success">空闲</span>
                                        <span th:if="${courier.currentStatus == 'offline'}" class="badge badge-danger">离线</span>
                                        <span th:if="${courier.currentStatus == 'busy'}" class="badge badge-warning">忙碌</span>
                                    </td>
                                    <td th:text="${#temporals.format(courier.lastLogin, 'yyyy-MM-dd HH:mm')}">2023-06-22 15:30</td>
                                    <td>
                                        <a th:href="@{'/admin/couriers/' + ${courier.courierId}}" class="btn btn-sm btn-primary">
                                            <i class="fas fa-eye"></i>
                                        </a>
                                    </td>
                                </tr>
                                <tr th:if="${couriers == null || couriers.isEmpty()}">
                                    <td colspan="8" class="text-center">暂无配送员数据</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        <script>
            function refreshData() {
                location.reload();
            }

            function searchCouriers() {
                const searchTerm = document.getElementById('searchInput').value.toLowerCase();
                const rows = document.querySelectorAll('.data-table tbody tr');

                rows.forEach(row => {
                    const text = row.textContent.toLowerCase();
                    if(text.includes(searchTerm)) {
                        row.style.display = '';
                    } else {
                        row.style.display = 'none';
                    }
                });
            }

            // 在页面加载时标记当前菜��为活动状态
            document.addEventListener('DOMContentLoaded', function() {
                document.querySelectorAll('.sidebar-menu a').forEach(a => {
                    a.classList.remove('active');
                });
                document.getElementById('menu-couriers').classList.add('active');
            });
        </script>
    </div>
</body>
</html>
